﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;//Please add references
namespace SCS.DAL
{
	/// <summary>
	/// 数据访问类:JX_StuInfo
	/// </summary>
	public partial class JX_StuInfo
	{
		public JX_StuInfo()
		{}
		#region  Method



		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(SCS.Model.JX_StuInfo model)
		{
			StringBuilder strSql=new StringBuilder();
			StringBuilder strSql1=new StringBuilder();
			StringBuilder strSql2=new StringBuilder();
			if (model.StuId != null)
			{
				strSql1.Append("StuId,");
				strSql2.Append("'"+model.StuId+"',");
			}
			if (model.StuXH != null)
			{
				strSql1.Append("StuXH,");
				strSql2.Append("'"+model.StuXH+"',");
			}
			if (model.StuName != null)
			{
				strSql1.Append("StuName,");
				strSql2.Append("'"+model.StuName+"',");
			}
			if (model.StuSex != null)
			{
				strSql1.Append("StuSex,");
				strSql2.Append("'"+model.StuSex+"',");
			}
			if (model.StuBankCard != null)
			{
				strSql1.Append("StuBankCard,");
				strSql2.Append("'"+model.StuBankCard+"',");
			}
			if (model.ClassCode != null)
			{
				strSql1.Append("ClassCode,");
				strSql2.Append("'"+model.ClassCode+"',");
			}
			if (model.ClassName != null)
			{
				strSql1.Append("ClassName,");
				strSql2.Append("'"+model.ClassName+"',");
			}
			if (model.HeaderTeacherZGH != null)
			{
				strSql1.Append("HeaderTeacherZGH,");
				strSql2.Append("'"+model.HeaderTeacherZGH+"',");
			}
			if (model.HeaderTeacherName != null)
			{
				strSql1.Append("HeaderTeacherName,");
				strSql2.Append("'"+model.HeaderTeacherName+"',");
			}
			if (model.HeaderTeacherDepartmentCode != null)
			{
				strSql1.Append("HeaderTeacherDepartmentCode,");
				strSql2.Append("'"+model.HeaderTeacherDepartmentCode+"',");
			}
			if (model.SpeCode != null)
			{
				strSql1.Append("SpeCode,");
				strSql2.Append("'"+model.SpeCode+"',");
			}
			if (model.SpeName != null)
			{
				strSql1.Append("SpeName,");
				strSql2.Append("'"+model.SpeName+"',");
			}
			if (model.SpeLength != null)
			{
				strSql1.Append("SpeLength,");
				strSql2.Append(""+model.SpeLength+",");
			}
			if (model.GradeCode != null)
			{
				strSql1.Append("GradeCode,");
				strSql2.Append("'"+model.GradeCode+"',");
			}
			if (model.BranchSchoolCode != null)
			{
				strSql1.Append("BranchSchoolCode,");
				strSql2.Append("'"+model.BranchSchoolCode+"',");
			}
			if (model.BranchSchoolName != null)
			{
				strSql1.Append("BranchSchoolName,");
				strSql2.Append("'"+model.BranchSchoolName+"',");
			}
			if (model.FacultyCode != null)
			{
				strSql1.Append("FacultyCode,");
				strSql2.Append("'"+model.FacultyCode+"',");
			}
			if (model.FacultyName != null)
			{
				strSql1.Append("FacultyName,");
				strSql2.Append("'"+model.FacultyName+"',");
			}
			if (model.StuMark != null)
			{
				strSql1.Append("StuMark,");
				strSql2.Append(""+model.StuMark+",");
			}
			strSql.Append("insert into JX_StuInfo(");
			strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1));
			strSql.Append(")");
			strSql.Append(" values (");
			strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1));
			strSql.Append(")");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(SCS.Model.JX_StuInfo model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update JX_StuInfo set ");
			if (model.StuId != null)
			{
				strSql.Append("StuId='"+model.StuId+"',");
			}
			if (model.StuXH != null)
			{
				strSql.Append("StuXH='"+model.StuXH+"',");
			}
			if (model.StuName != null)
			{
				strSql.Append("StuName='"+model.StuName+"',");
			}
			else
			{
				strSql.Append("StuName= null ,");
			}
			if (model.StuSex != null)
			{
				strSql.Append("StuSex='"+model.StuSex+"',");
			}
			else
			{
				strSql.Append("StuSex= null ,");
			}
			if (model.StuBankCard != null)
			{
				strSql.Append("StuBankCard='"+model.StuBankCard+"',");
			}
			else
			{
				strSql.Append("StuBankCard= null ,");
			}
			if (model.ClassCode != null)
			{
				strSql.Append("ClassCode='"+model.ClassCode+"',");
			}
			if (model.ClassName != null)
			{
				strSql.Append("ClassName='"+model.ClassName+"',");
			}
			else
			{
				strSql.Append("ClassName= null ,");
			}
			if (model.HeaderTeacherZGH != null)
			{
				strSql.Append("HeaderTeacherZGH='"+model.HeaderTeacherZGH+"',");
			}
			else
			{
				strSql.Append("HeaderTeacherZGH= null ,");
			}
			if (model.HeaderTeacherName != null)
			{
				strSql.Append("HeaderTeacherName='"+model.HeaderTeacherName+"',");
			}
			if (model.HeaderTeacherDepartmentCode != null)
			{
				strSql.Append("HeaderTeacherDepartmentCode='"+model.HeaderTeacherDepartmentCode+"',");
			}
			else
			{
				strSql.Append("HeaderTeacherDepartmentCode= null ,");
			}
			if (model.SpeCode != null)
			{
				strSql.Append("SpeCode='"+model.SpeCode+"',");
			}
			if (model.SpeName != null)
			{
				strSql.Append("SpeName='"+model.SpeName+"',");
			}
			else
			{
				strSql.Append("SpeName= null ,");
			}
			if (model.SpeLength != null)
			{
				strSql.Append("SpeLength="+model.SpeLength+",");
			}
			else
			{
				strSql.Append("SpeLength= null ,");
			}
			if (model.GradeCode != null)
			{
				strSql.Append("GradeCode='"+model.GradeCode+"',");
			}
			if (model.BranchSchoolCode != null)
			{
				strSql.Append("BranchSchoolCode='"+model.BranchSchoolCode+"',");
			}
			else
			{
				strSql.Append("BranchSchoolCode= null ,");
			}
			if (model.BranchSchoolName != null)
			{
				strSql.Append("BranchSchoolName='"+model.BranchSchoolName+"',");
			}
			if (model.FacultyCode != null)
			{
				strSql.Append("FacultyCode='"+model.FacultyCode+"',");
			}
			else
			{
				strSql.Append("FacultyCode= null ,");
			}
			if (model.FacultyName != null)
			{
				strSql.Append("FacultyName='"+model.FacultyName+"',");
			}
			if (model.StuMark != null)
			{
				strSql.Append("StuMark="+model.StuMark+",");
			}
			int n = strSql.ToString().LastIndexOf(",");
			strSql.Remove(n, 1);
			strSql.Append(" where ");
			int rowsAffected=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rowsAffected > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete()
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from JX_StuInfo ");
			strSql.Append(" where " );
			int rowsAffected=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rowsAffected > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public SCS.Model.JX_StuInfo GetModel()
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1  ");
			strSql.Append(" StuId,StuXH,StuName,StuSex,StuBankCard,ClassCode,ClassName,HeaderTeacherZGH,HeaderTeacherName,HeaderTeacherDepartmentCode,SpeCode,SpeName,SpeLength,GradeCode,BranchSchoolCode,BranchSchoolName,FacultyCode,FacultyName,StuMark ");
			strSql.Append(" from JX_StuInfo ");
			strSql.Append(" where " );
			SCS.Model.JX_StuInfo model=new SCS.Model.JX_StuInfo();
			DataSet ds=DbHelperSQL.Query(strSql.ToString());
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public SCS.Model.JX_StuInfo DataRowToModel(DataRow row)
		{
			SCS.Model.JX_StuInfo model=new SCS.Model.JX_StuInfo();
			if (row != null)
			{
				if(row["StuId"]!=null)
				{
					model.StuId=row["StuId"].ToString();
				}
				if(row["StuXH"]!=null)
				{
					model.StuXH=row["StuXH"].ToString();
				}
				if(row["StuName"]!=null)
				{
					model.StuName=row["StuName"].ToString();
				}
				if(row["StuSex"]!=null)
				{
					model.StuSex=row["StuSex"].ToString();
				}
				if(row["StuBankCard"]!=null)
				{
					model.StuBankCard=row["StuBankCard"].ToString();
				}
				if(row["ClassCode"]!=null)
				{
					model.ClassCode=row["ClassCode"].ToString();
				}
				if(row["ClassName"]!=null)
				{
					model.ClassName=row["ClassName"].ToString();
				}
				if(row["HeaderTeacherZGH"]!=null)
				{
					model.HeaderTeacherZGH=row["HeaderTeacherZGH"].ToString();
				}
				if(row["HeaderTeacherName"]!=null)
				{
					model.HeaderTeacherName=row["HeaderTeacherName"].ToString();
				}
				if(row["HeaderTeacherDepartmentCode"]!=null)
				{
					model.HeaderTeacherDepartmentCode=row["HeaderTeacherDepartmentCode"].ToString();
				}
				if(row["SpeCode"]!=null)
				{
					model.SpeCode=row["SpeCode"].ToString();
				}
				if(row["SpeName"]!=null)
				{
					model.SpeName=row["SpeName"].ToString();
				}
				if(row["SpeLength"]!=null && row["SpeLength"].ToString()!="")
				{
					model.SpeLength=int.Parse(row["SpeLength"].ToString());
				}
				if(row["GradeCode"]!=null)
				{
					model.GradeCode=row["GradeCode"].ToString();
				}
				if(row["BranchSchoolCode"]!=null)
				{
					model.BranchSchoolCode=row["BranchSchoolCode"].ToString();
				}
				if(row["BranchSchoolName"]!=null)
				{
					model.BranchSchoolName=row["BranchSchoolName"].ToString();
				}
				if(row["FacultyCode"]!=null)
				{
					model.FacultyCode=row["FacultyCode"].ToString();
				}
				if(row["FacultyName"]!=null)
				{
					model.FacultyName=row["FacultyName"].ToString();
				}
				if(row["StuMark"]!=null && row["StuMark"].ToString()!="")
				{
					model.StuMark=int.Parse(row["StuMark"].ToString());
				}
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select StuId,StuXH,StuName,StuSex,StuBankCard,ClassCode,ClassName,HeaderTeacherZGH,HeaderTeacherName,HeaderTeacherDepartmentCode,SpeCode,SpeName,SpeLength,GradeCode,BranchSchoolCode,BranchSchoolName,FacultyCode,FacultyName,StuMark ");
			strSql.Append(" FROM JX_StuInfo ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" StuId,StuXH,StuName,StuSex,StuBankCard,ClassCode,ClassName,HeaderTeacherZGH,HeaderTeacherName,HeaderTeacherDepartmentCode,SpeCode,SpeName,SpeLength,GradeCode,BranchSchoolCode,BranchSchoolName,FacultyCode,FacultyName,StuMark ");
			strSql.Append(" FROM JX_StuInfo ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM JX_StuInfo ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.User_ID desc");
			}
			strSql.Append(")AS Row, T.*  from JX_StuInfo T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/*
		*/

		#endregion  Method
		#region  MethodEx

		#endregion  MethodEx
	}
}

